<!--
 * @Author: xiaotiwen
 * @Date: 2020-05-19 16:04:26
 * @LastEditTime: 2020-07-21 18:06:25
 * @LastEditors: xiaotiwen
 * @FilePath: \eduweb\src\views\practiceManagement\scheduleSetting\schedule.vue
 * @Description: 排课明细
-->
<template>
    <div class="schedule">
        <div class="schedule_one">
            <h2 class="schedule_titles">{{$t('scheduleSetting.title.scheduleTitle2')}}</h2>
            <div class="schedule_form">
                <el-form :model="form" ref="form" :rules="rules" label-width="150px">
                    <el-row>
                        <el-col :span="8">
                            <el-form-item :label="$t('fundingManagement.label.courseProgramNumber')" prop="subCourseNo">
                                <el-input v-model="form.subCourseNo" :placeholder="$t('fundingManagement.tips.plzInput')" :disabled="true"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('scheduleSetting.label.courseName')" prop="courseName">
                                <el-input v-model="form.courseName" :placeholder="$t('fundingManagement.tips.plzInput')" :disabled="true"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('practiceTask.label.number')" prop="confirmCount">
                                <el-input-number v-model="form.confirmCount" style="width:100%;" :disabled="true"></el-input-number>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item :label="$t('practiceReworkManagement.label.courseDateStart')" prop="courseDateStart">
                                <el-date-picker v-model="form.courseDateStart" @change="timeChange" format="yyyy-MM-dd" value-format="timestamp" type="date" :placeholder="$t('message.plzSelect')" style="width:100%;" :disabled="editFlag" :picker-options="pickerOptions1"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('practiceReworkManagement.label.courseDateEnd')" prop="courseDateEnd">
                                <el-date-picker v-model="form.courseDateEnd" @change="timeChange" format="yyyy-MM-dd" value-format="timestamp" type="date" :placeholder="$t('message.plzSelect')" style="width:100%;" :disabled="editFlag" :picker-options="pickerOptions2"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('scheduleSetting.label.weekendFlag')" prop="weekendFlag">
                                <DictSelect v-model="form.weekendFlag" :data="options.weekendFlag" :placeholder="$t('message.plzSelect')" :clearable="false" :disabled="isEdit || editFlag"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item :label="$t('scheduleSetting.label.mainTeacher')" prop="mainTeacher">
                                <TeacherSelect v-model="form.mainTeacher" :showAllTeacher="true" :conditionNotNull="false" :queryOnlyByTeacherId="true"></TeacherSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('scheduleSetting.label.instructorTeacher')" prop="instructorTeacher">
                                <SelfTeacherSelect :condition="teacherSelectCondition" v-model="form.instructorTeacher" :showAllTeacher="true" :conditionNotNull="false" :queryOnlyByTeacherId="true" :multiple="true"></SelfTeacherSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('scheduleSetting.label.estimatedFund')" prop="funds">
                                <el-input v-model="form.funds" :placeholder="$t('fundingManagement.tips.plzInput')" maxlength="10" :disabled="editFlag"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item :label="$t('scheduleSetting.label.practiceCategory')" prop="practiceCategory">
                                <DictSelect v-model="form.practiceCategory" @change="practiceCategoryChange" :data="options.practiceCategory"
                                            :placeholder="$t('message.plzSelect')" :clearable="false" :disabled="isEdit || editFlag"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('scheduleSetting.label.nature')" prop="practiceNature">
                                <el-select v-model="form.practiceNature" :placeholder="$t('message.plzSelect')" :clearable="false" :disabled="isEdit || editFlag" style="width:100%;">
                                    <el-option v-for="item in options.practiceNature" :label="item.label" :value="item.value" :key="item.value" :disabled="item.disabled"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('practiceManagement.label.practiceArea')" prop="baseArea">
                                <DictSelect v-model="form.baseArea" @change="areaChange" :data="options.baseArea" :placeholder="$t('message.plzSelect')" :clearable="false" :disabled="isEdit || editFlag"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" v-if="form.baseArea==='410001'">
                            <el-form-item :label="$t('label.campus')" prop="compus">
                                <DictSelect v-model="form.compus" :data="options.compus" :placeholder="$t('message.plzSelect')" :clearable="false" :disabled="isEdit || editFlag"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" v-else>
                            <el-form-item :label="$t('fundingManagement.label.courseAddr')" prop="courseAddr">
                                <el-select v-model="form.courseAddr" allow-create default-first-option filterable :placeholder="$t('message.plzSelect')" :disabled="isEdit || editFlag" maxlength="30">
                                    <el-option v-for="item in options.courseAddr" :key="item.value" :label="item.baseName" :value="item.baseName"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('fundingManagement.label.practiceDays')" prop="practiceDays">
                                <el-input v-model="form.practiceDays" style="width:100%;" :disabled="true"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item :label="$t('scheduleSetting.label.practiceRemark')" prop="practiceRemark">
                                <el-input v-model="form.practiceRemark" :placeholder="$t('fundingManagement.tips.plzInput')" maxlength="200" type="textarea" resize="none" :rows="4" :disabled="editFlag"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item :label="$t('scheduleSetting.label.chooseCourseRemark')" prop="chooseCourseRemark">
                                <el-input v-model="form.chooseCourseRemark" :placeholder="$t('fundingManagement.tips.plzInput')" maxlength="200" type="textarea" resize="none" :rows="4" :disabled="editFlag"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" v-if="editFlag">
                            <el-form-item :label="$t('scheduleSetting.btn.attachTypes')">
                                <span>{{ attachTypes }}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="16" v-if="editFlag">
                            <el-form-item prop="fields" label-width="60px">
                                <el-upload ref="uploads" class="upload-demo" :before-upload="beforeUpload" :headers="{'X-Token': $store.state.session.sessionid}" action="/api/commonservice/obsfile/uploadfile" :data="{bucketname: 'face', folderpath: 'file'}" :on-success="uploadDone" :limit="1" :on-exceed="handleExceed" :file-list="fileList">
                                    <div class="schedule_upload">
                                        <el-button size="small" type="primary">{{$t('scheduleSetting.btn.upload')}}</el-button>
                                        <div class="schedule_upload_div">{{$t('scheduleSetting.tips.uploadTips')}}</div>
                                    </div>
                                </el-upload>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <div class="schedule_btn">
                <el-button type="primary" class="schedule_btn_btn1" @click="save">{{$t('message.save')}}</el-button>
                <el-button @click="cancel">{{$t('message.cancel')}}</el-button>
            </div>
        </div>
        <div class="schedule_panel" v-if="panelFlag">
            <arrange-panel ref="arrangePanel" :class-id="active.ids" :ids="active.id" :edit-type="active.type" :objs="active" :period-error="2" teacher-swap @back="cancel" :calendar-id="queryParams.condition.calendar"></arrange-panel>
        </div>
        <!-- <panelPart v-if="editFlag"></panelPart> -->
    </div>
</template>

<script>
import UTILS from 'common/src/utils/utils'
import { getValue } from "common/src/api/commonParam";
import ArrangePanel from "./ArrangePanel";
import panelPart from './panelPart';
import { saveData,editPublishSchedule, getDetail, uploads } from 'common/src/api/practiceManagement/scheduleSetting';
import Calendars from "common/src/api/calendars.js";
import commonMixins from '../commonMixins';
import { udgPtBaseInfoList } from "common/src/api/practiceManagement/internSetup";
import moment from 'moment';
import SelfTeacherSelect from '../selfUtil/SelfTeacherSelect';
export default {
    // 组件名称
    name: 'schedule',
    // 局部注册的组件
    components: {
        ArrangePanel,
        panelPart,
        SelfTeacherSelect
    },
    mixins: [commonMixins],
    // 组件参数 接收来自父组件的数据
    props: {
        // scheduleFlag: { // 校内外实践 校外true 校内 false
        //     type: Boolean,
        //     default: false
        // },
        isEdit: {//是否是发布修改状态
            type: Boolean,
            default: false
        },
        editFlag: { // 是否可编辑 可编辑false， 不可编辑true
            type: Boolean,
            default: false
        },
        objs: {
            type: Object,
            default() {
                return { yearTerm: '', id: '', classId: '', isSchedule: '', courseOpenAcademyId: '' };
            }
        }
    },
    // 组件状态值
    data() {
        return {
            teacherSelectCondition:{
                codeList: [],
                pageNum_: 1,
                pageSize_: 50
            },
            panelFlag: false,
            charactersFlag: false,
            attachTypes: '',
            address: '', // 实习范围
            startInTerm: '',
            endInTerm: '',
            form: {
                subCourseNo: '', // 课程号
                courseName: '', // 关联课程信息
                confirmCount: '', // 课程人数
                courseDateStart: '', // 上课开始时间
                courseDateEnd: '', // 上课结束时间
                weekendFlag: '', // 是否含双休日
                mainTeacher: '', // 主要负责教师
                mainTeacherName: '', // 主要负责教师姓名
                mainTeacherJobno: '', // 主要负责教师编号
                instructorTeacher: [], // 其他指导教师
                instructorTeacherName: '', // 其他指导教师姓名
                instructorTeacherJobno: '', // 其他指导老师编号：
                funds: '', // 经费
                practiceCategory: '', // 实践类别
                practiceNature: '', // 实践性质
                baseArea: '', // 实习范围
                compus: '', // 校区
                courseAddr: '', // 上课地点
                practiceDays: '', // 实习天数
                practiceRemark: '', // 实习备注
                chooseCourseRemark: '', // 选课备注
                udgPtAttachT: {},
                attachType: '',
                teachWeeks: '' // 教学周数
            },
            fileList: [],
            active: {
                id: null,
                type: 'add',
                ids: '',
                dataId: '',
                yearTerm: ''
            },
            rules: {
                subCourseNo: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur'] }], // 课程号
                courseName: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur'] }],  // 关联课程信息
                confirmCount: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur'] }],  // 课程人数
                courseDateStart: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }],  // 上课开始时间
                courseDateEnd: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }],  // 上课结束时间
                weekendFlag: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }],  // 是否含双休日
                mainTeacher: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }],  // 主要负责教师
                practiceCategory: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }],  // 实践类别
                practiceNature: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }],  // 实践性质
                baseArea: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }],  // 实习范围
                compus:[{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur'] }],
                courseAddr: [
                    { required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur'] },
                    { validator: this.validCourseAddre, trigger: ['change', 'blur'] }
                ],  // 上课地点
                // practiceDays: [
                //     { required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] },
                //     { pattern: /^[1-9]\d*$/, message: this.$t('scheduleSetting.tips.mustHaveTime'), trigger: ['blur', 'change'] }
                // ], // 实习天数
                attachType: [{ required: true, message: this.$t('practiceReworkManagement.tips.mustWrite'), trigger: ['blur', 'change'] }], // 上传类型
                fields: [{ validator: this.validateFile, trigger: ['change'] }], // 文件上传
                funds: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('scheduleSetting.tips.inputNonZero'), trigger: ['blur'] }], // 经费
                practiceRemark: [{ validator: this.validateRemark, trigger: 'change' }], // 实习备注
                chooseCourseRemark: [{ validator: this.validateRemark, trigger: 'change' }] //  选课备注
            },
            options: {
                practiceNature: [  // 实践性质
                    { label: this.$t('fundingManagement.label.concentrated'), value: 'CENTRALIZE', disabled: false },
                    { label: this.$t('fundingManagement.label.dispersion'), value: 'DISPERSE', disabled: false }
                ],
                practiceCategory: [
                    // { label: '生产实习（专业实习）', value: '01' },
                    // { label: '认识实习', value: '02' },
                    // { label: '计算机上机', value: '03' },
                    // { label: '课程设计（大作业）', value: '04' },
                    // { label: '金工实习', value: '05' },
                    // { label: '军训', value: '06' }
                ],
                weekendFlag: [
                    { label: this.$t('scheduleSetting.status.incloud'), value: 'Y' },
                    { label: this.$t('scheduleSetting.status.unIncloud'), value: 'N' }
                ],
                baseArea: [],
                attachType: [
                    { label: this.$t('scheduleSetting.btn.attachType1'), value: 'DISPERSE' },
                    { label: this.$t('scheduleSetting.btn.attachType2'), value: 'CENTRALIZE' }
                ],
                compus: [], // 校区
                courseAddr: []
            },
            queryParams: {
                condition: {
                    calendar: ''
                }
            },
            pickerOptions1: {
                disabledDate: time => {
                    if (this.form.courseDateEnd) {
                        return time.getTime() > new Date(this.form.courseDateEnd).getTime();
                    }
                }
            },
            pickerOptions2: {
                disabledDate: time => {
                    if (this.form.courseDateStart) {
                        return time.getTime() < new Date(this.form.courseDateStart).getTime();
                    }
                }
            }
        };
    },
    // 计算属性
    computed: {},
    // 侦听器
    watch: {
        'form.weekendFlag': {
            handler(newVal, oldVal) {
                this.timeChange();
            },
            deep: true
        }
    },
    /**
    * 在实例初始化之后，组件属性计算之前，如data属性等
    */
    created() {
        this.initOptions({ X_XQ: 'compus' });
    },
    /**
    * 在挂载开始之前被调用：相关的 render 函数首次被调用。
    */
    mounted() {
        let p1 = getValue('arrange_default_term');
        p1.then(res => {
            this.queryParams.condition.calendar = res.data;
        });
        this.getDetails();
    },
    // 组件方法
    methods: {
        cancel() { // 返回
            this.$emit('cancel', 'refresh');
        },
        validateFile(rule, value, callback) {
            if (!this.$refs.uploads.uploadFiles.length) {
                callback(new Error(this.$t('scheduleSetting.tips.plzUpload')));
            } else {
                callback()
            }
        },
        validCourseAddre(rule, value, callback) {
            if (value && value.length > 30) {
                callback(new Error(this.$t('scheduleSetting.tips.maxLimit')));
            } else {
                callback()
            }
        },
        save() {  // 保存
            if (this.editFlag) {  // 保存上传
                let length = this.$refs.uploads.uploadFiles.length;
                if (length === 0) {
                    this.$message({ type: 'warning', message: this.$t('scheduleSetting.tips.plzUpload2') });
                } else {
                    let jsonData = {
                        id: this.objs.id,
                        attachType: this.form.attachType,
                        udgPtAttachT: this.form.udgPtAttachT
                    };
                    uploads(jsonData).then(res => {
                        if (res && res.code !== 200) {
                            this.$message({ message: res.msg, type: 'warning' });
                            return;
                        }
                        this.$message({ message: this.$t('scheduleSetting.tips.uploadSuccess'), type: 'success' });
                        this.$emit('cancel', 'refresh');
                    });
                }
                return;
            }
            this.$refs.form.validate((valid) => { // 保存排课明细
                if (valid) {
                    let jsonData = {}
                    for (const key in this.form) {
                        if (this.form.hasOwnProperty(key)) {
                            this.$set(jsonData, key, this.form[key]);
                        }
                    }
                    if (typeof this.form.instructorTeacher === 'object' && this.form.instructorTeacher.length>0) {
                        let instructorTeacherName = null;
                        let instructorTeacherJobno = null;
                        this.form.instructorTeacher.forEach(t=>{
                            instructorTeacherName = instructorTeacherName?instructorTeacherName+","+t.name:t.name;
                            instructorTeacherJobno = instructorTeacherJobno?instructorTeacherJobno+","+t.code:t.code;
                        })
                        this.$set(jsonData, 'instructorTeacherName', instructorTeacherName);
                        this.$set(jsonData, 'instructorTeacherJobno', instructorTeacherJobno);
                    }
                    if (typeof this.form.mainTeacher === 'object' && this.form.mainTeacher.name) {
                        this.$set(jsonData, 'mainTeacherName', this.form.mainTeacher.name);
                        this.$set(jsonData, 'mainTeacherJobno', this.form.mainTeacher.code);
                    } else if (typeof this.form.mainTeacher === 'string' && !this.form.mainTeacher) {
                        this.$set(jsonData, 'mainTeacherName', '');
                        this.$set(jsonData, 'mainTeacherJobno', '');
                    }
                    delete jsonData.instructorTeacher;
                    delete jsonData.mainTeacher;
                    this.$set(jsonData, 'yearTerm', this.objs.yearTerm);
                    this.$set(jsonData, 'id', this.objs.id);
                    this.$set(jsonData, 'teachWeeks', this.teachWeeks);
                    if(this.isEdit){
                        //发布修改
                        editPublishSchedule(jsonData).then(res => {
                            if (res && res.code !== 200) {
                                this.$message({ message: res.msg, type: 'warning' });
                                return;
                            }
                            this.$message({ message: this.$t('message.saveSuccess'), type: 'success' });
                            this.$emit('cancel', 'refresh');
                        });
                    }else{
                        saveData(jsonData).then(res => {
                            if (res && res.code !== 200) {
                                this.$message({ message: res.msg, type: 'warning' });
                                return;
                            }
                            this.$message({ message: this.$t('message.saveSuccess'), type: 'success' });
                            this.$emit('cancel', 'refresh');
                        });
                    }
                }
            });

        },
        areaChange(val) {
            if (parseInt(val) !== 410001) {
                this.$refs.form.clearValidate("compus")
                this.getAddress();
                this.form.courseAddr = null;
            }else{
                this.form.compus = null;
                this.$refs.form.clearValidate("courseAddr")
            }
            this.$emit('input', val);
        },
        handlerSwapTeacher() {

        },
        timeChange() { // 时间校验
            this.getAddress();
            if (this.$refs.arrangePanel) {
              this.$refs.arrangePanel.showRoomTable = false;
            }
            if (this.form.courseDateStart && this.form.courseDateEnd && this.form.weekendFlag) {
                this.calDateInTerm(this.form.courseDateStart,this.form.courseDateEnd)
                if (this.form.weekendFlag === 'Y') {
                    this.form.practiceDays = (this.form.courseDateEnd - this.form.courseDateStart) / (86400000) + 1
                } else {
                    let s = new Date();
                    let e = new Date();
                    s.setTime(this.form.courseDateStart);
                    e.setTime(this.form.courseDateEnd);
                    let s_t_w = s.getDay();
                    let e_t_w = e.getDay();
                    //相差天数
                    let diffDay = (this.form.courseDateEnd - this.form.courseDateStart) / (86400000) + 1;
                    //计算有几个完整的周
                    let weeks = Math.floor(diffDay / 7);
                    let lengths = diffDay - weeks * 7;
                    let num = 0;
                    if (lengths > 0) {
                        for (let i = 0; i < lengths; i++) {
                            if (s_t_w + i === 0 || s_t_w + i === 6 || s_t_w + i === 7) {
                                num++;
                            }
                        }
                    }
                    this.form.practiceDays = diffDay - weeks * 2 - num;
                }
            } else {
                this.form.practiceDays = 0;
            }
        },
        getDetails() { // 数据回显
            let jsons = {
                UDG_TRAINNING_POSITION: 'baseArea',
                UDG_PRACTICE_CATEGORY: 'practiceCategory',
            }
            this.initOptions(jsons);
            getDetail({ id: this.objs.id }).then(res => {
                if (res.data) {
                    for (const key in this.form) {
                        if (res.data.hasOwnProperty(key) && res.data[key]) {
                            if ((key === 'courseDateEnd' && res.data.courseDateEnd) || (key === 'courseDateStart' && res.data.courseDateStart)) {
                                // this.form[key] = new Date(res.data[key] + ' 00:00:00').getTime();
                                this.form[key] = Number(moment(res.data[key] + ' 00:00:00').format('x'));
                            } else {
                                this.form[key] = res.data[key];
                            }
                        }
                    }

                    //2021/06/29 王国民老师说，排课不要面板
                    /*if (parseInt(this.form.baseArea) === 410001) {
                        this.panelFlag = true;
                    } else {
                        this.panelFlag = false;
                    }*/

                    if (this.form.practiceNature === 'CENTRALIZE') { // 集中
                        this.form.attachType = 'CENTRALIZE';
                        this.attachTypes = this.$t('scheduleSetting.btn.attachType2');
                    } else if (this.form.practiceNature === 'DISPERSE') { // 分散
                        this.form.attachType = 'DISPERSE';
                        this.attachTypes = this.$t('scheduleSetting.btn.attachType1');
                    }
                    if (res.data.instructorTeacherName && res.data.instructorTeacherJobno) {
                        // this.form.instructorTeacher = `${res.data.instructorTeacherName}(${res.data.instructorTeacherJobno})`;
                        let names = res.data.instructorTeacherName.split(",")
                        let codes = res.data.instructorTeacherJobno.split(",")
                        this.teacherSelectCondition = {codeList: codes};
                        for(let i=0;i<names.length;i++){
                            let teacher = {
                                name:names[i],
                                code:codes[i]
                            }
                            this.form.instructorTeacher.push(teacher)
                        }
                    }
                    if (res.data.mainTeacherName && res.data.mainTeacherJobno) {
                        this.form.mainTeacher = `${res.data.mainTeacherName}(${res.data.mainTeacherJobno})`;
                    }
                    this.active.yearTerm = res.data.yearTerm;
                    this.form.confirmCount = res.data.studentCount;
                    let obj = res.data.udgPtAttachT;
                    if (obj && obj.attachName && obj.attachSize && obj.attachPath) {
                        let jsons = {
                            name: obj.attachName,
                            size: obj.attachSize,
                            url: obj.attachPath
                        };
                        this.fileList.push(jsons);
                    }
                    this.active.id = res.data.teachingClassId;
                    this.active.dataId = this.objs.id;
                    this.active.ids = res.data.teachingClassId;
                }
            });
        },
        handleExceed(files, fileList) { // 文件超出个数限制时的钩子
            this.$message.warning(
                UTILS.i18nReplace(this.$t('dispersionPracticeApply.tips.fileTips'),{
                    first:files.length,
                    second:files.length +fileList.length,
                    third: 1
                })
            );
        },
        uploadDone(res, file) {
            let jsons = {
                attachName: file.name,
                attachSize: file.size,
                attachPath: Object.values(file.response.data)[0].objectkey
            };
            this.form.udgPtAttachT = [jsons];
        },
        beforeUpload(file) {
            return UTILS.checkFile(
                file,
                {
                    name: '.xlsx,.xls',
                    size: '10'
                },
                this
            )
        },
        practiceCategoryChange(val) { // 实践性质
            if (parseInt(val) !== 1) {
                if (this.form.practiceNature === 'DISPERSE') {
                    this.form.practiceNature = '';
                }
                this.$set(this.options.practiceNature[1], 'disabled', true);
            } else {
                this.$set(this.options.practiceNature[1], 'disabled', false);
            }
        },
        getAddress(val = '') {
            if (this.form.courseDateStart && this.form.courseDateEnd && this.form.baseArea && parseInt(this.form.baseArea) !== 410001) {
                let startTime = new Date();
                startTime.setTime(this.form.courseDateStart);
                startTime = this.formatDate(startTime, 'yyyy-MM-dd');
                let endTime = new Date();
                endTime.setTime(this.form.courseDateEnd);
                endTime = this.formatDate(endTime, 'yyyy-MM-dd');
                let jsonData = {
                    baseName: val,
                    signConFlag: "",
                    status: 'APPROVED',
                    effectStatus: 'Y',
                    academyId: this.objs.courseOpenAcademyId,
                    brilliantBaseFlag: "",
                    validDateStart: startTime,
                    validDateEnd: endTime,
                    practiceArea: this.form.baseArea,
                    isPlaceManage: 'Y'
                }
                udgPtBaseInfoList(1, 50, jsonData).then(res => {
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' });
                        return;
                    }
                    this.options.courseAddr = res.data.records;
                });
            }
        },
        remoteMethod(baseName) {
            if (baseName.length > 30) {
                return;
            }
            setTimeout(() => {
                this.getAddress(baseName);
            }, 200);
            if (!baseName) {
                this.form.courseAddr = '';
            }
        },
        calDateInTerm(start,end){
            if(start && end){
                Calendars.getSchoolCalendarByTime(start).then(res => {
                    let weekendFlag = this.form.weekendFlag;
                    this.startInTerm = res.data.week;
                    if (this.$refs.arrangePanel) {
                      let satrtInfo = weekendFlag === 'N' && (res.data.weekDay === 6 || res.data.weekDay === 7) ? (res.data.week+1) : res.data.week;
                      this.$refs.arrangePanel.startInfo = satrtInfo;
                    }
                    Calendars.getSchoolCalendarByTime(end).then(res1 => {
                        this.endInTerm = res1.data.week
                        if (this.$refs.arrangePanel) {
                          let endInfo = res1.data.week;
                          this.$refs.arrangePanel.endInfo = endInfo;
                        }
                        if(this.startInTerm > this.endInTerm){
                            this.$message({ message:this.$t('scheduleSetting.tips.sameYear'), type: 'warning' });
                            return;
                        }
                        this.teachWeeks = this.endInTerm - this.startInTerm + 1
                    })
                })
            }
            return;
        }
    }
};
</script>
<style lang="scss" scoped>
.schedule {
    &_one {
        padding-top: 20px;
        background-color: #fff;
    }
    h2 {
        border-bottom: solid #ccc 1px;
        font-size: 18px;
        font-weight: bold;
        padding-left: 40px;
        height: 40px;
        line-height: 40px;
    }
    &_form {
        padding: 20px;
    }
    &_btn {
        padding: 20px;
        border-top: solid #ccc 1px;
        display: flex;
        flex-direction: row-reverse;
        &_btn1 {
            margin-left: 10px;
        }
    }
    &_upload {
        display: flex;
        align-items: center;
        &_div {
            margin-left: 10px;
        }
    }
    &_panel {
        margin-top: 20px;
        padding: 20px;
        background-color: #fff;
    }
    ::v-deep .el-upload-list__item {
        width: 220px;
    }
}
</style>
